//
//  ImageGridCell.m
//  CGPDFTest
//
//  Created by Emo, on 2024/5/20.
//

#import "ImageGridCell.h"

@interface ImageGridCell ()

@property (nonatomic, strong) UIImageView * imgView;

@property (nonatomic, strong) UILabel * countLabel;

@end

@implementation ImageGridCell

- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        [self setupUI];
    }
    return self;
}


- (void)setupUI {
    [self.contentView addSubview:self.imgView];
    [self.contentView addSubview:self.countLabel];
}

- (void)configDataWithImage:(UIImage *)image index:(NSInteger)index {
    self.imgView.image = image;
    self.countLabel.text = [NSString stringWithFormat:@"%ld", index];
}


- (void)layoutSubviews {
    [super layoutSubviews];
    
    self.imgView.frame = self.contentView.bounds;
    self.countLabel.frame = CGRectMake(0, 0, 18, 18);
//    [self.imgView mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.edges.mas_equalTo(self.contentView);
//    }];
//    
//    [self.countLabel mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.top.mas_equalTo(self.imgView);
//        make.height.mas_equalTo(15);
//        make.width.mas_greaterThanOrEqualTo(15);
//    }];
}



#pragma mark -- Lazy --
- (UIImageView *)imgView {
    if (!_imgView) {
        _imgView = [[UIImageView alloc] init];
    }
    return _imgView;
}

- (UILabel *)countLabel {
    if (!_countLabel) {
        _countLabel = [[UILabel alloc] init];
        _countLabel.textAlignment = NSTextAlignmentCenter;
        _countLabel.font = [UIFont systemFontOfSize:14];
        _countLabel.textColor = [UIColor whiteColor];
        _countLabel.backgroundColor = [UIColor colorWithRed:122/255 green:122/255 blue:122/255 alpha:0.8];
    }
    return _countLabel;
}


@end
